package leetcode.D2000.T1288;

import java.util.Arrays;

/**
 * @File Info: leetcode -- <Solution>
 * @Author: 18362
 * @Create: 2022-02-24 14:20:20 星期四
 */
class Solution {
    public int removeCoveredIntervals(int[][] intervals) {
        Arrays.sort(intervals, (o1, o2) -> {
            if (o1[0] != o2[0])
                return o1[0] - o2[0];
            return o2[1] - o1[1];
        });
        int left = intervals[0][0], right = intervals[0][1], sum = 0;
        for (int i=1; i<intervals.length; ++i) {
            int[] interval = intervals[i];
            if (right >= interval[1])
                sum++;
            else {
                left = interval[0];
                right = interval[1];
            }
        }
        return intervals.length - sum;
    }
}
